package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "vote")
@ApiModel(value = "投票记录", description = "投票字段")
@org.hibernate.annotations.Table(appliesTo = "vote", comment = "投票记录表")
public class Vote {

    @Id
    @ApiModelProperty(value = "主键", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @ApiModelProperty(value = "用户ID", example = "1", hidden = true)
    @Column(columnDefinition = "bigint comment '用户ID'")
    private Long userId;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "房间ID", example = "3")
    @Column(columnDefinition = "bigint comment '房间ID'")
    private Long roomId;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "投票：-1#跌,0#平,1#涨", example = "-1")
    @Column(columnDefinition = "int comment '投票：-1#跌,0#平,1#涨'")
    private Integer updown;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Transient
    @ApiModelProperty(value = "涨数量", example = "1")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private Integer up;

    @Transient
    @ApiModelProperty(value = "跌数量", example = "2")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private Integer down;

    @Transient
    @ApiModelProperty(value = "平数量", example = "2")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private Integer flat;
}
